<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <title>在线支付</title>
    <link rel="stylesheet" href="__CSS__/supermarket.css" />
    <link rel="stylesheet" href="__CSS__/orderDetail.css" />
    <link rel="stylesheet" href="__CSS__/wxzf.css" />
    <script src="__JS__/jquery2.1.1.min.js"></script>
    <script src="__JS__/layer.min.js"></script>
    <script>
    //调用微信JS api 支付
        //调用微信JS api 支付
    /*
        function jsApiCall()
        {
            WeixinJSBridge.invoke(
                'getBrandWCPayRequest',
                <?php echo $jsApiParameters; ?>,
                function(res){
                    WeixinJSBridge.log(res.err_msg);
                    reg=/cancel/i;
                    ok=/ok/i;
                    if(reg.test(res.err_msg)){
                 	  layer.msg('付款取消');
                    }else if(){
                    	 layer.msg('付款成功');
                    	 <if condition="$type eq 1">
                    	 setTimeout(function(){
                    		 location.href="{:U('Orders/orders')}";
                    	 })
                    	 <else/>
                    	 setTimeout(function(){
                    		 location.href="{:U('Index/index',array('r'=>'my'))}";
                    	 })
                    	 </if>
                    }else{
                    	alert(res.err_code+res.err_desc+res.err_msg);
                    }
                    //alert("{$jsApiParameters}");
                }
            );
        }


        */
    function callpay() {
        window.location.href = "/Wx/OnlinePay/wxPay"+'?id={$orderId}'+'&type={$type}';
        // window.location.href = "/Wx/OnlinePay/wxPay/type/1/id/"+{$orderId};
    }
    </script>

</head>

<body>
<div id="pay" style="display:<if condition="$pwd eq 1">block<else/>none;</if>" >
    <div class="_top">
        <?php
        $r = $_GET['r'];
        $url = 'window.location.href="/Wx/Index/index/r/order"';
        if($r){
            $url = 'window.history.go(-1);';
        }
        if($_GET['ref']){
            $url = $_GET['ref'];
        }
        ?>
        <div class="_left_top" onclick="location.href='{$url}'"></div>
        <div class="_title_top">在线支付</div>
        <div class="_right_top nobackground"></div>
    </div>
    <div class="_content">
      <!-- <div class="_son_title ub noborder border_bottom1 ">
            <div class="ub-f1 text-l"><if condition="$type eq 1">订单<else/>充值</if>金额</div>
            <div class="ub-f1 text-r margin_right10">{//$needPay}元</div>
        </div> -->
        <if condition="($type eq 1) and($payType eq '')">
        <div class="_son_title ub noborder border_bottom1 margin_top10">
            <div class="title_left_ico margin_left10  " style="background-image: url(__IMG__/search/qianbao.png)"></div>
            <div class="ub-f1 text-l">钱包余额支付</div>
            <div class="mui-input-row mui-radio  margin_right10 margin_top5">

                <input  id="pay3" class="payType" name="checkbox" value="3" type="radio">
                <label for="pay3" class="check-label"></label>
            </div>
        </div>

        <div class="_son_title ub height35 ">
            <div class="ub-f1 text-l font90 col_9">您的账户余额为<span class="red">{$balance}</span></div>
        </div>
        </if>
        <div class="_son_title ub height35 margintop10">
            <div class="ub-f1 text-l  ">使用第三方平台支付</div>
        </div>
        <div class="_son_title ub noborder border_bottom1 ">
            <div class="title_left_ico margin_left10 " style="background-image: url(__IMG__/search/weixin.png)"></div>
            <div class="ub-f1 text-l">微信支付</div>
            <div class="mui-input-row mui-radio  margin_right10 margin_top5">
                <input  id="pay2" class="payType"  name="checkbox" value="2" type="radio">
                <label for="pay2" class="check-label"></label>
            </div>
        </div>
        <div class="_son_title ub noborder border_bottom1 " style="display: none;">
            <div class="title_left_ico margin_left10 " style="background-image: url(__IMG__/search/zfb.png)"></div>
            <div class="ub-f1 text-l">支付宝</div>
            <div class="mui-input-row mui-radio  margin_right10 margin_top5">
                <input id="pay1" class="payType"  name="checkbox" value="1" type="radio">
                <label for="pay1" class="check-label"></label>
            </div>
        </div>
        <!--
        <div class="_son_title ub noborder border_bottom1 ">
            <div class="title_left_ico margin_left10 ali_ico"></div>
            <div class="ub-f1 text-l">支付宝支付</div>
            <div class="mui-input-row mui-radio  margin_right10 margin_top5">
                <input class="payType" name="checkbox" value="1" type="radio">
            </div>
        </div>
        -->
        <div class="_son_title ub height35 margintop10 noborder nobackground _center">
            <div class="ub-f1 text-c"><span class="submit" onclick="showPay()">确认支付</span></div>
        </div>
    </div>
    <!--浮动层-->
    <if condition="$type == 1">
    <div class="ftc_wzsf">
        <div class="srzfmm_box">
            <div class="qsrzfmm_bt clear_wl">
                <img src="__IMG__/xx_03.jpg" class="tx close fl">

                <if condition="$userPhoto">
                            <?php   if($userPhoto== ''){  ?>
                  <img src="__IMG__/member.jpg" style="height: 28px;width:28px; border-radius: 28px; margin-top: 10px;" class="fl touxian">
                <?php }elseif(strpos($userPhoto,"http://") === 0){  ?>
          <img src="{$userPhoto}" style="height: 28px;width:28px; border-radius: 28px; margin-top: 10px;" class="fl touxian">
                <?php }elseif(substr($userPhoto,7) != 'http://'){  ?>
                 <img src="/{$userPhoto}" style="height: 28px;width:28px; border-radius: 28px; margin-top: 10px;" class="fl touxian">
                <?php
            }
            ?>
                    <span class="fl">请输入支付密码</span>
                    <else/>
                    <img src="__IMG__/jftc_03.jpg" style="height: 28px;width:28px; border-radius: 28px; margin-top: 10px;" class="fl touxian"><span class="fl">请输入支付密码</span>
                </if>
            </div>
            <div class="zfmmxx_shop">
                <div class="mz">
                    {$shopName}
                </div>
                <div class="wxzf_price">
                    ￥00.00
                </div>
            </div>
            <div class="blank_yh">
                <img src="__IMG__/alpay.png" class="fl"><span class="fl ml5">选择其它方式付款</span><img src="__IMG__/jftc_09.jpg" class="fr">
            </div>
            <ul class="mm_box">
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
            </ul>
        </div>
        <div class="numb_box">
            <div class="xiaq_tb">
                <img src="__IMG__/jftc_14.jpg" height="10">
            </div>
            <ul class="nub_ggg">
                <li>
                    <a href="javascript:void(0);">1</a>
                </li>
                <li>
                    <a href="javascript:void(0);" class="zj_x">2</a>
                </li>
                <li>
                    <a href="javascript:void(0);">3</a>
                </li>
                <li>
                    <a href="javascript:void(0);">4</a>
                </li>
                <li>
                    <a href="javascript:void(0);" class="zj_x">5</a>
                </li>
                <li>
                    <a href="javascript:void(0);">6</a>
                </li>
                <li>
                    <a href="javascript:void(0);">7</a>
                </li>
                <li>
                    <a href="javascript:void(0);" class="zj_x">8</a>
                </li>
                <li>
                    <a href="javascript:void(0);">9</a>
                </li>
                <li>
                    <span></span>
                </li>
                <li>
                    <a href="javascript:void(0);" class="zj_x">0</a>
                </li>
                <li>
                    <span class="del"> <img src="__IMG__/jftc_18.jpg"   ></span>
                </li>
            </ul>
        </div>
        <div class="hbbj"></div>
    </div>
    </if>
</div>
<div id="setpayPwd" style="display:<if condition="$pwd eq 0">block<else/>none;</if>" >
 <div class="_top">
        <div class="_left_top"></div>
        <div class="_title_top">设置支付密码</div>
        <div class="_right_top nobackground"></div>
    </div>
    <div class="_content">
        <div class="_son_title ub noborder border_bottom1" style="height:50px; line-height:50px;">
            <div class=" text-l col_9">
            支付密码</div>
            <div class="ub-f1 inputpwd"><input type="password" name="payPwd" id="payPwd" placeholder='请输入6位数字密码'/></div>
        </div>
        <div class="_son_title ub height35 "  style="height:50px; line-height:50px;">
            <div class=" text-l font90 col_9">重复支付密码</div>
             <div class="ub-f1 inputpwd"><input type="password" name="payPwds" id="payPwds" placeholder='重复输入6位数字密码'/></div>
        </div>
        <div class="_son_title ub height35 margintop10 noborder nobackground _center">
            <div class="ub-f1 text-c "><span class="submit" onclick="setpayPwd()">保存</span></div>
        </div>
    </div>
</div>
<input  type="hidden" name="orderids" id="orderids" value="{$orderids}" />
<input  type="hidden" name="payStatus" id="payStatus" value="0" />
<input  type="hidden" name="isrepeat" id="isrepeat" value="0" />
</body>
<script type="text/javascript">
function showPay() {
	 var payType = $(".payType:checked").val();

     if (payType == null || payType == '' || payType == 'undefined') {
       	layer.msg('请选择付款方式');
         return;
     }

     //余额支付
	if(payType==3){
		 $(".ftc_wzsf").show();
	}else if(payType==1){
	 	layer.msg('支付宝支付正在建设中...');
        return;
	}else if(payType==2){
		callpay();
	}
}
$(function() {
    $('.wxzf_price').text('￥{$needPay}');

    //出现浮动层
    $('.blank_yh').on('click', function() {
        $(".ftc_wzsf").hide();
    });

    $(".ljzf_but").on('click', function() {
        $(".ftc_wzsf").show();
    });
    //关闭浮动
    $(".close").on('click', function() {
        $(".ftc_wzsf").hide();
    });
    //数字显示隐藏
    $(".xiaq_tb").on('click', function() {
        $(".numb_box").slideUp(500);
    });
    $(".mm_box").on('click', function() {
        $(".numb_box").slideDown(500);
    });
    //----
    var i = 0;
    var payPwd = '';
    $(".nub_ggg li a").on('click', function() {
        var payStatus = $('#payStatus').val();
        //判断已经已经是6位密码
        if (payStatus == 1) {
        	layer.msg('正在处理中');
            return;
        }
        i++;
        if (i < 6) {
            payPwd = payPwd + $(this).text();
            $(".mm_box li").eq(i - 1).addClass("mmdd");
        } else {
            $('#payStatus').val(1);
            payPwd = payPwd + $(this).text();
            $(".mm_box li").eq(i - 1).addClass("mmdd");
            if (payPwd == '' || payPwd == null || payPwd.length != 6) {
                //alert(payPwd);
                return;
            }
            layer.msg('正在付款...',{icon:16});
            var orderids=$('#orderids').val();
 		   $.ajax({
	           type: "POST",
	           url: "{:U('Wx/Confirm/balancePay')}",
	           data: {pwd:payPwd,orderids:orderids},
	           dataType: "json",
	           success: function(data){
	        	   layer.closeAll();
	        	   if(data.status==0){
	        		   layer.msg(data.msg);
	        		   setTimeout(function(){

	        			   location.href="{:U('/Wx/Index/index/r/order')}";
	        		   },1000);
	        	   }else if(data.status==-1||data.status==-3||data.status==-2){
	        		   $(".mm_box li").removeClass("mmdd");
	        		   i=0;
	        		   payPwd='';
	        		   $('#payStatus').val(0);
	        		   layer.msg(data.msg);
	        		   layer.msg(data.msg);
	        		   return;
	        	   }else if(data.status==-4){
	        		   layer.msg(data.msg);
	        		   setTimeout(function(){
                            <if condition="$_GET['ref']">
                                location.href="/Wx/Score/scoreShop";
                                <else/>
                                location.href="{:U('/Wx/Index/index/r/order')}";
                            </if>

	        		   },1000);
	        	   }
	            }
	       });

            //密码错误处理、/*
            //
            // $(".mm_box li").removeClass("mmdd");
            // $('#payStatus').val(0);
            // payPwd = '';
            // i = 0;
            //*/
        }
    });

    $(".nub_ggg li .del").on('click', function() {
        if (i > 0) {
            i--;
            $(".mm_box li").eq(i).removeClass("mmdd");
            payPwd = payPwd.substring(0, payPwd.length - 1);
            i == 0;
            $('#payStatus').val(0);
        }
    });

});

//设置支付密码
function setpayPwd(){
		var paypwd=$('#payPwd').val();
		var paypwds=$('#payPwds').val();
		if(paypwd.length!=6||paypwds.length!=6){
			layer.msg('密码长度不对');
			return;
		}
		if(paypwd!=paypwds){
			layer.msg('重复密码不正确');
			return;
		}
    var re = /^\d+$/;


    if(!re.test(paypwd)){
        layer.msg('密码只能是数字');
        return;
    }

    if(isNaN(paypwd)||isNaN(paypwds)){
			layer.msg('密码只能是6位数字');
			return;
		}
		layer.msg('正在保存...',{icon:16});
		   $.ajax({
	           type: "POST",
	           url: "{:U('Wx/Confirm/setPayPwd')}",
	           data: {pwd:paypwds},
	           dataType: "json",
	           success: function(data){
	        	   layer.closeAll();
	        			if(data.status==0){
	        				layer.msg(data.msg);
	        				$('#setpayPwd').hide();
	        				$('#pay').show();
	        			}else if(data.status==-1||data.status==-2){
	        				layer.msg(data.msg);
	        			}
	            }
	       });
}
</script>

</html>
